<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="UTF-8">
		<title>会员资料</title>
		<script type="text/javascript" src="../layui/layui.js"></script>
		<link rel="stylesheet" href="../layui/css/layui.css">
		<link rel="stylesheet" href="../css/backer/MemberInfo.css" />
		<script type="text/javascript" src="../js/jquery-1.12.4.js" ></script>
	</head>
	<body>
		<form action="" method="">
			<input hidden name="uid" th:value="${session.user.uid}">
			<div class="head-div">
				<i class="layui-icon layui-icon-list">&nbsp;用户信息</i>
			</div>
			<div class="maintemplate"><br /><br />
				<div class="">
					<div class="inline-block lable">联系人：</div>
					<div class="inline-block"><input name="linkman" type="text" class="input-linkman" th:value="${session.user.linkman}" /></div>
				</div>
				<div class="">
					<div class="inline-block lable">社区昵称：</div>
					<div class="inline-block"><input name="communityName" type="text" class="communitynickname" th:value="${session.user.communityName}"/></div>
				</div>
				<div style="margin: 10px 0px 10px 0px;">
					<div class="inline-block lable">性别：</div>
					<div class="inline-block">
						<input type="radio" name="sex" th:selected="${session.user.sex==1}" style="margin-left: 5px;"checked="checked" class="sex" value="true" />&nbsp;&nbsp;男
						<input type="radio" name="sex" th:selected="${session.user.sex==0}" style="margin-left: 30px;" class="sex" value="false" />&nbsp;&nbsp;女
					</div>
				</div>
				<div class="">
					<div class="inline-block lable">旧密码：</div>
					<div class="inline-block"><input type="password" name="oldpassword" placeholder="输入旧密码" class="password" />
						<input type="button" value="验证" class="changephone"/>
						<input hidden name="isdiffent"  value="false">
						<input hidden name="pwd"  th:value="${session.user.password}">
					</div>
				</div>
				<div class="">
					<div class="inline-block lable">新密码：</div>
					<div class="inline-block"><input type="password"  name="password" placeholder="输入新密码"  class="password" />
					</div>
				</div>
				<div class="">
					<div class="inline-block lable">手机号：</div>
					<div class="inline-block">
						<input class="phone" name="phone" th:value="${session.user.phone}"/>
					</div>
				</div>
				<div class="" >
					<div class="inline-block lable">设置头像：</div>
					<div class="layui-upload" style="padding-left: 160px;">
						<button type="button" class="layui-btn" id="test1">上传图片</button>
						<div class="layui-upload-list">
							<img style="width: 100px;height: 100px;" class="layui-upload-img" id="demo1">
							<p id="demoText"></p>
						</div>
					</div>
				</div>
				<div class="grayhr"></div>
				<input id="getbtn" type="button" class="getbtn" value="提交"/>
			</div>
			<br /><br />
			
		</form>
	</body>

	<script>
		var imgcount = 0;
		layui.use(['upload'], function () {
			var upload = layui.upload;
			//普通图片上传
			var uploadInst = upload.render({
				elem: '#test1'
				,url: '../upimg/upload2' //改成您自己的上传接口
				,size:0
				,auto:false
				,bindAction:"#getbtn"
				,choose: function(obj){
					//预读本地文件示例，不支持ie8
					obj.preview(function(index, file, result){
						$('#demo1').attr('src', result); //图片链接（base64）
					});
				}
				,before: function(obj){
					//预读本地文件示例，不支持ie8
					obj.preview(function(index, file, result){
						$('#demo1').attr('src', result); //图片链接（base64）
					});
				}
				,done: function(res){
					$.ajax({
						url:'http://localhost:8080/backer/useredit',
						type:'post',
						dataType:'json',
						data:$("form").serialize(),
						success:function(data){
							if(data){
								alert("修改成功！");
								location.href='http://localhost:8080/backer/syshomepage';
							}else{
								alert("修改失败！");
							}
						}
					})
				}
				,error: function(){
					//演示失败状态，并实现重传
					var demoText = $('#demoText');
					demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
					demoText.find('.demo-reload').on('click', function(){
						uploadInst.upload();
					});
				}
			});
		});
	</script>

	<script>
		//判断两次密码是否存在并且一致
		$(".changephone").click(function(){
			$.ajax({
				url:'http://localhost:8080/backer/isdiff',
				type:'post',
				dataType:'json',
				data:{'oldpwd':$("[name=oldpassword]").val()},
				success:function (data){
					if (data){
						$("[name=isdiffent]").val("true");
						alert("密码正确！")
					}else{
						$("[name=isdiffent]").val("false");
						alert("密码不一致，请重试！");
					}
				}
			})
		})


		//判断有没有空的文本框，提交表单
		/*$(".getbtn").click(function(){
			if($("[name=linkman]").val()=="" ){
				alert("联系人不能为空！");
				return false;
			}else if($("[name=communityName]").val()==""){
				alert("社区名称不能为空！");
				return false;
			}else if($("[name=oldpassword]").val()==""){
				alert("旧密码不能为空！");
				return false;
			}else if($("[name=password]").val()==""){
				alert("新密码不能为空！");
				return false;
			}else if($("[name=phone]").val()==""){
				alert("手机号不能为空！");
				return false;
			}else if($("[name=isdiffent]").val()=="false"){
				alert("旧密码不正确！");
				return false;
			}else{
				$.ajax({
					url:'http://localhost:8080/backer/useredit',
					type:'post',
					dataType:'json',
					data:$("form").serialize(),
					success:function(data){
						if(data){
							alert("修改成功！");
							location.href='http://localhost:8080/backer/syshomepage';
						}else{
							alert("修改失败！");
						}
					}
				})
			}

		});*/
		$(".ischeckbox").click(function(){
			if($("#checkboxs").attr("v")==0){
				$("#checkboxs").attr("checked","checked");
				$("#checkboxs").attr("v","1");
			}else{
				$("#checkboxs").removeAttr("checked");
				$("#checkboxs").attr("v","0");
			}
		})

		
	</script>
</html>
